<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="java.io.*,java.sql.*,java.util.*,java.net.*,java.text.*"%>
<%@ page import="com.yuxin.common.util.*" %>
<%@ page import="com.yuxin.core.exception.SiteRuntimeException" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String dataId = request.getParameter("id");// 数据ID
    Connection conn = DBUtil.getConnection();
    try{
        Map content = DBUtil.findById(conn,"P_GOODS",dataId);
        // 替换图片路径
        if(StringUtils.hasText(content.get("DESCRIPTION"))){
            String contentValue = StringUtils.getText(content.get("DESCRIPTION")).replaceAll("/\\[yx_img_sever\\]/file/", request.getAttribute("ctx") + "/file/");
            content.put("DESCRIPTION",contentValue);
        }
    	int pClass = Integer.parseInt(content.get("P_CLASS").toString());
    	switch(pClass){
        	case 1:
        		content.put("CLASS_NAME","中餐");
        		break;
        	case 2:
        		content.put("CLASS_NAME","西餐");
        		break;
        	case 3:
        		content.put("CLASS_NAME","蛋糕甜");
        		break;
        	case 4:
        		content.put("CLASS_NAME","自助餐");
        		break;
        	case 5:
        		content.put("CLASS_NAME","火锅");
        		break;
        	case 6:
        		content.put("CLASS_NAME","酒店");
        		break;
        	case 7:
        		content.put("CLASS_NAME","旅游");
        		break;
        	case 8:
        		content.put("CLASS_NAME","电影票");
        		break;
        	case 9:
        		content.put("CLASS_NAME","教育培训");
        		break;
        	case 10:
        		content.put("CLASS_NAME","体检保健");
        		break;
        	case 11:
        		content.put("CLASS_NAME","美容SPA");
        		break;
        	case 12:
        		content.put("CLASS_NAME","美发");
        		break;
    	}
        // 页面标题
        request.setAttribute("titleName","详情");
        request.setAttribute("content",content);
        request.setAttribute("store_index",content.get("TRADE_ID"));
        request.setAttribute("ENCODE_TITLE", URLEncoder.encode(content.get("TITLE")+"","UTF-8"));
    }catch (Exception e){
        e.printStackTrace();
        throw new SiteRuntimeException(e);
    }finally {
        DBUtil.close(conn);
    }
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>${content.TITLE}</title>
    <meta name="Keywords" content="中信信用卡平台" />
    <meta name="Description" content="${content.TITLE}"/>
    <meta name="robots" content="all"/>
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="format-detection" content="telephone=no"/>
    <meta http-equiv="cleartype" content="on"/>
    <link rel="icon" type="image/png" href="images/favicon.ico">
    <%@ include file="/site/css.jsp" %>
</head>
<body>
<div id="page">
    <%@ include file="/site/header_nav.jsp" %>
    <div id="container">
        <div class="article-content liebiao-x">
            <c:if test="${content.TITLE_IMG !=null && content.TITLE_IMG !=''}">
                <div class="title-img"><img src="${ctx}${content.TITLE_IMG}"/></div>
            </c:if>
	        <h1>${content.TITLE}</h1>
        	<div class="article-time">
            	<div class="price">￥${content.PRICE}</div>
		        <div>类型：${content.CLASS_NAME}</div>
		        <div class="small">发布时间：${content.UPDATE_TIME}</div>
        	</div>
            <div class="box-btn" >
                <a  href="javascript:void(0)" class="button big orange" onclick="addToCart();">添加到购物车</a>
            </div>
            <div class="box-btn clearfix">
                <a href="${ctx}/site/gouwuche.jsp" style="width:48%;" class="button blue left">查看购物车</a>
                <a href="javascript:void(0)" class="button blue right" style="width:48%;"  onclick="favorite()">收藏</a>
            </div>
            <div class="article-content">
	            ${content.CONTENT}
	        </div>
        </div>
    </div>
    <%@ include file="/site/footer.jsp" %>
</div>
<%@ include file="/site/js.jsp" %>
</body>
<script>
    var width = $(window).width() -20;
    $("#container table").each(function(){
        if($(this).width() > width){
            //兼容低版本浏览器 暂时不适用wrap
            $(this).width(width);//.wrap("<div style='"+width+"px;overflow:auto;'></div> ");
        }
    });

    $("#container img").each(function(){
        if($(this).width() > width){
            //兼容低版本浏览器 暂时不适用wrap
            $(this).width(width);//.wrap("<div style='"+width+"px;overflow:auto;'></div> ");
        }
    });

    /*** 添加到购物车 ***/
    function addToCart(){
        var cookieStr = appUtil.getCookie("productList",{"path":"/site"}) || "{}";
		var productList = JSON.parse(cookieStr);
        if(productList["${content.ID}"]){
        	productList["${content.ID}"] = productList["${content.ID}"]*1 + 1;
        }else{
        	productList["${content.ID}"] = "1";
        }
        appUtil.setCookie("productList",JSON.stringify(productList),{"path":"${ctx}/site"});
        appUtil.alert("添加成功！");
        return false;
    }
    /***添加到收藏***/
	function favorite(){
		if("${isLogin}" == "false"){
            appUtil.alert("请先登录！");
            setTimeout(function(){
                window.location.href = "${ctx}/site/denglu.jsp?url="+encodeURIComponent("${ctx}/site/shangpin_x.jsp?id=${param.id}");
            },1500);
		}else{
	        $.post(ctx+"/site/site.action.jsp", {"action": "favorite", "id": "${content.ID}"}, function (result) {
	            if(result.isSuccess){
	                appUtil.alert("收藏成功！");
	            }else{
	                appUtil.alert(result.error);
	            }
	            return false;
	        });
    	}
	}
</script>
</html>